package com.puman.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Repository;

import com.core.BaseDaoImpl;
import com.core.Pager;
import com.puman.bean.M_company;
import com.puman.dao.CompanyDao;

@Repository("companyDao")
public class CompanyDaoImpl extends BaseDaoImpl<M_company> implements CompanyDao {

	@Override
	public List<M_company> getList(Integer supplier_id) {
		String sql = "select cp.id,cp.name,cp.mobile,cp.linkman,cp.invitecode,cp.address," +
				" cp.create_date,cp.create_user_id,cp.create_user_name,cp.modify_date," +
				" cp.modify_user_id,cp.modify_user_name,cp.plan_targets,cp.city,cp.county," +
				" cp.province,cp.image_url " +
				" from m_company cp where cp.id in" +
				" (select c.company_id from m_contract c where c.supplier_id ="+supplier_id+" group by c.company_id)" +
				" order by cp.modify_date desc";
		List<M_company> list = getSession().createSQLQuery(sql).addEntity(M_company.class).list();
		return list;
	}

	@Override
	public List<M_company> getListLike(Integer supplier_id, String name) {
		String sql = "select cp.id,cp.name,cp.mobile,cp.linkman,cp.invitecode,cp.address," +
				" cp.create_date,cp.create_user_id,cp.create_user_name,cp.modify_date," +
				" cp.modify_user_id,cp.modify_user_name,cp.plan_targets,cp.city,cp.county," +
				" cp.province,cp.image_url " +
				" from m_company cp where cp.id in" +
				" (select c.company_id from m_contract c where c.supplier_id ="+supplier_id+" group by c.company_id)" +
				" and cp.name like '%"+name+"%' order by cp.modify_date desc";
		List<M_company> list = getSession().createSQLQuery(sql).addEntity(M_company.class).list();
		return list;
	}

}
